import uvicorn
from fastapi import FastAPI, Request
from app import sqlite_service, chromadb_service

app = FastAPI()


@app.get('/sqlite')
async def sqlite():
	return sqlite_service.get_data()


# http://127.0.0.1:8000/annoy?key=1&topK=2
@app.get('/annoy')
async def annoy(key: int, topK: int = 3):
	from app import annoy_service
	return annoy_service.query(key, topK)


# http://127.0.0.1:8000/chromadb?key=key-2&topK=2
@app.get('/chromadb')
async def chromadb_get(key: str, topK: int = 3):
	return chromadb_service.get(key, topK)


# curl -H "Content-Type: application/json" -X POST -d '{"keys": ["key-22", "key-23"], "metadatas": [{"key":"key-22"},{"key":"key-23"}], "embeddings": [[0.14018404483795166,-0.7040528059005737,-1.0875355005264282,0.9583468437194824,0.08253048360347748],[-0.03161163255572319,-0.8659502863883972,-1.211888074874878,-0.08404525369405746,0.07117623835802078]]}' "http://127.0.0.1:8000/chromadb"
@app.post('/chromadb')
async def chromadb_post(ids: list[str], metadatas: list[dict], embeddings: list[list[float]]):
	chromadb_service.add(ids, metadatas, embeddings)
	return 'SUCCESS'


# curl -H "Content-Type: application/json" -X PUT -d '{"keys": ["key-22", "key-23"], "metadatas": [{"key":"key-22"},{"key":"key-23"}], "embeddings": [[0.14018404483795166,-0.7040528059005737,-1.0875355005264282,0.9583468437194824,0.08253048360347748],[-0.03161163255572319,-0.8659502863883972,-1.211888074874878,-0.08404525369405746,0.07117623835802078]]}' "http://127.0.0.1:8000/chromadb"
@app.put('/chromadb')
async def chromadb_put(keys: list[str], metadatas: list[dict], embeddings: list[list[float]]):
	chromadb_service.update(keys, metadatas, embeddings)
	return 'SUCCESS'


# curl -H "Content-Type: application/json" -X DELETE -d '["key-22", "key-23"]' "http://127.0.0.1:8000/chromadb"
@app.delete('/chromadb')
async def chromadb_delete(keys: list[str]):
	chromadb_service.delete(keys)
	return 'SUCCESS'


# if __name__ == '__main__':
# 	uvicorn.run(app, host='0.0.0.0', port=8000, log_level='info')
